package com.open.cloud.rbac.utils;

import java.util.HashMap;
import java.util.Map;

/**
 * @author ：sun_bin
 * @date ：Created in 2019/6/6 10:37
 */
public class ThreadLocalUtil {

  private static final ThreadLocal<Map<String, Object>> THREAD_LOCAL =
      new ThreadLocal<>();

  public static void set(String key, Object value) {
    Map<String, Object> map = THREAD_LOCAL.get();
    if (map == null) {
      map = new HashMap<>(16);
      THREAD_LOCAL.set(map);
    }
    map.put(key, value);
  }

  public static Object get(String key) {
    Map<String, Object> map = THREAD_LOCAL.get();
    if (map == null) {
      map = new HashMap<>(16);
      THREAD_LOCAL.set(map);
    }
    return map.get(key);
  }

  public static void remove() {
    THREAD_LOCAL.remove();
  }
}
